<template>
    <div>
        <h1>登录</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <th align="right">账号</th>
                    <th><input type="text" v-model="queryinfo.AName"></th>
                </tr>
                <tr>
                    <th align="right">密码</th>
                    <th><input type="password" v-model="queryinfo.APwd"></th>
                </tr>
                <tr>
                    <th align="right"></th>
                    <th><input type="button" value="登录" class="btn btn-primary" @click="login"></th>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref,reactive,onMounted } from 'vue';
import axios from 'axios';
import moment, { lang } from 'moment';
import { useRoute,useRouter } from 'vue-router';
import { useAdminStare } from '@/stores/admin';
const route=useRoute()
const router=useRouter()
const adc=useAdminStare()
//登录的时候后端所需要的参数
let queryinfo:any=reactive({
    AName:'',
    APwd:''
})

const login=()=>{
    if(queryinfo.AName==""){
        alert("账号不能为空")
        return
    }
    if(queryinfo.APwd==""){
        alert("密码不能为空")
        return
    }
    axios({
        url:'/api/Admin/AdminLogin',
        method:'get',
        params:queryinfo
    })
    .then((res)=>{
        console.log(res);
        if(res.data==-1){
            alert("用户名不存在")
            return
        }
        if(res.data==-2){
            alert("密码不正确")
            return
        }
       
        alert("登录成功")
        adc.useinfo=res.data
        router.push('/houseadd')
        
    })
}

</script>

<style scoped>

</style>